import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class PageBackendGoodsAdd():
    def __init__(self, driver):
        self.driver = driver

#输入商品名称
    def ele_goods_name(self):
        time.sleep(1)
        self.driver.find_element(By.NAME, 'goods_name').send_keys('私人飞机')

    #选择商品分类
    def ele_goods_classify(self):
        ele = self.driver.find_element_by_name('cat_id')
        select = Select(ele)
        select.select_by_value('174')
        time.sleep(2)
    #点击【确认】按钮（添加）
    def ele_submit_affirm(self):
        self.driver.find_element(By.XPATH, '//div[@id="tabbody-div"]/form/div/input[2]').click()

   #进入右侧mainframe
    def ele_main_frame(self):
        self.driver.switch_to.frame('main-frame')

    # 退出frame
    def ele_frame_out(self):
        self.driver.switch_to.default_content()

    def add_goods(self):
        self.ele_main_frame()
        self.ele_goods_name()
        self.ele_goods_classify()
        self.ele_submit_affirm()
        self.ele_frame_out()